home *** CD-ROM | disk | FTP | other *** search
/ RSPB Wildlife Explorers Mammal Guide / Mammals Guide.iso / mac / bird_info.swf / scripts / FUIComponentSymbol.as < prev    next >
Text File  |  2008-07-31  |  9KB  |  328 lines

  1. function FUIComponentClass()
  2. {
  3.    this.init();
  4. }
  5. FUIComponentClass.prototype = new MovieClip();
  6. FUIComponentClass.prototype.init = function()
  7. {
  8.    this.enable = true;
  9.    this.focused = false;
  10.    this.useHandCursor = false;
  11.    this._accImpl = new Object();
  12.    this._accImpl.stub = true;
  13.    this.styleTable = new Array();
  14.    if(_global.globalStyleFormat == undefined)
  15.    {
  16.       _global.globalStyleFormat = new FStyleFormat();
  17.       globalStyleFormat.isGlobal = true;
  18.       _global._focusControl = new Object();
  19.       _global._focusControl.onSetFocus = function(oldFocus, newFocus)
  20.       {
  21.          oldFocus.myOnKillFocus();
  22.          newFocus.myOnSetFocus();
  23.       };
  24.       Selection.addListener(_global._focusControl);
  25.    }
  26.    if(this._name != undefined)
  27.    {
  28.       this._focusrect = false;
  29.       this.tabEnabled = true;
  30.       this.focusEnabled = true;
  31.       this.tabChildren = false;
  32.       this.tabFocused = true;
  33.       if(this.hostStyle == undefined)
  34.       {
  35.          globalStyleFormat.addListener(this);
  36.       }
  37.       else
  38.       {
  39.          this.styleTable = this.hostStyle;
  40.       }
  41.       this.deadPreview._visible = false;
  42.       this.deadPreview._width = this.deadPreview._height = 1;
  43.       this.methodTable = new Object();
  44.       this.keyListener = new Object();
  45.       this.keyListener.controller = this;
  46.       this.keyListener.onKeyDown = function()
  47.       {
  48.          this.controller.myOnKeyDown();
  49.       };
  50.       this.keyListener.onKeyUp = function()
  51.       {
  52.          this.controller.myOnKeyUp();
  53.       };
  54.       for(var _loc3_ in this.styleFormat_prm)
  55.       {
  56.          this.setStyleProperty(_loc3_,this.styleFormat_prm[_loc3_]);
  57.       }
  58.    }
  59. };
  60. FUIComponentClass.prototype.setEnabled = function(enabledFlag)
  61. {
  62.    this.enable = arguments.length <= 0 ? true : enabledFlag;
  63.    this.tabEnabled = this.focusEnabled = enabledFlag;
  64.    if(!this.enable && this.focused)
  65.    {
  66.       Selection.setFocus(undefined);
  67.    }
  68. };
  69. FUIComponentClass.prototype.getEnabled = function()
  70. {
  71.    return this.enable;
  72. };
  73. FUIComponentClass.prototype.setSize = function(w, h)
  74. {
  75.    this.width = w;
  76.    this.height = h;
  77.    this.focusRect.removeMovieClip();
  78. };
  79. FUIComponentClass.prototype.setChangeHandler = function(chng, obj)
  80. {
  81.    this.handlerObj = obj != undefined ? obj : this._parent;
  82.    this.changeHandler = chng;
  83. };
  84. FUIComponentClass.prototype.invalidate = function(methodName)
  85. {
  86.    this.methodTable[methodName] = true;
  87.    this.onEnterFrame = this.cleanUI;
  88. };
  89. FUIComponentClass.prototype.cleanUI = function()
  90. {
  91.    if(this.methodTable.setSize)
  92.    {
  93.       this.setSize(this.width,this.height);
  94.    }
  95.    else
  96.    {
  97.       this.cleanUINotSize();
  98.    }
  99.    this.methodTable = new Object();
  100.    delete this.onEnterFrame;
  101. };
  102. FUIComponentClass.prototype.cleanUINotSize = function()
  103. {
  104.    for(var _loc2_ in this.methodTable)
  105.    {
  106.       this._loc2_();
  107.    }
  108. };
  109. FUIComponentClass.prototype.drawRect = function(x, y, w, h)
  110. {
  111.    var _loc4_ = this.styleTable.focusRectInner.value;
  112.    var _loc5_ = this.styleTable.focusRectOuter.value;
  113.    if(_loc4_ == undefined)
  114.    {
  115.       _loc4_ = 16777215;
  116.    }
  117.    if(_loc5_ == undefined)
  118.    {
  119.       _loc5_ = 0;
  120.    }
  121.    this.createEmptyMovieClip("focusRect",1000);
  122.    this.focusRect.controller = this;
  123.    this.focusRect.lineStyle(1,_loc5_);
  124.    this.focusRect.moveTo(x,y);
  125.    this.focusRect.lineTo(x + w,y);
  126.    this.focusRect.lineTo(x + w,y + h);
  127.    this.focusRect.lineTo(x,y + h);
  128.    this.focusRect.lineTo(x,y);
  129.    this.focusRect.lineStyle(1,_loc4_);
  130.    this.focusRect.moveTo(x + 1,y + 1);
  131.    this.focusRect.lineTo(x + w - 1,y + 1);
  132.    this.focusRect.lineTo(x + w - 1,y + h - 1);
  133.    this.focusRect.lineTo(x + 1,y + h - 1);
  134.    this.focusRect.lineTo(x + 1,y + 1);
  135. };
  136. FUIComponentClass.prototype.pressFocus = function()
  137. {
  138.    this.tabFocused = false;
  139.    this.focusRect.removeMovieClip();
  140.    Selection.setFocus(this);
  141. };
  142. FUIComponentClass.prototype.drawFocusRect = function()
  143. {
  144.    this.drawRect(-2,-2,this.width + 4,this.height + 4);
  145. };
  146. FUIComponentClass.prototype.myOnSetFocus = function()
  147. {
  148.    this.focused = true;
  149.    Key.addListener(this.keyListener);
  150.    if(this.tabFocused)
  151.    {
  152.       this.drawFocusRect();
  153.    }
  154. };
  155. FUIComponentClass.prototype.myOnKillFocus = function()
  156. {
  157.    this.tabFocused = true;
  158.    this.focused = false;
  159.    this.focusRect.removeMovieClip();
  160.    Key.removeListener(this.keyListener);
  161. };
  162. FUIComponentClass.prototype.executeCallBack = function()
  163. {
  164.    this.handlerObj[this.changeHandler](this);
  165. };
  166. FUIComponentClass.prototype.updateStyleProperty = function(styleFormat, propName)
  167. {
  168.    this.setStyleProperty(propName,styleFormat[propName],styleFormat.isGlobal);
  169. };
  170. FUIComponentClass.prototype.setStyleProperty = function(propName, value, isGlobal)
  171. {
  172.    if(value == "")
  173.    {
  174.       return undefined;
  175.    }
  176.    var _loc19_ = parseInt(value);
  177.    if(!isNaN(_loc19_))
  178.    {
  179.       value = _loc19_;
  180.    }
  181.    var _loc18_ = arguments.length <= 2 ? false : isGlobal;
  182.    if(this.styleTable[propName] == undefined)
  183.    {
  184.       this.styleTable[propName] = new Object();
  185.       this.styleTable[propName].useGlobal = true;
  186.    }
  187.    if(this.styleTable[propName].useGlobal || !_loc18_)
  188.    {
  189.       this.styleTable[propName].value = value;
  190.       if(!this.setCustomStyleProperty(propName,value))
  191.       {
  192.          if(propName == "embedFonts")
  193.          {
  194.             this.invalidate("setSize");
  195.          }
  196.          else if(propName.substring(0,4) == "text")
  197.          {
  198.             if(this.textStyle == undefined)
  199.             {
  200.                this.textStyle = new TextFormat();
  201.             }
  202.             var _loc15_ = propName.substring(4,propName.length);
  203.             var _loc17_ = _loc15_.substring(0,1);
  204.             _loc17_ = _loc17_.toLowerCase();
  205.             _loc15_ = _loc17_ + _loc15_.substring(1,_loc15_.length);
  206.             this.textStyle[_loc15_] = value;
  207.             this.invalidate("setSize");
  208.          }
  209.          else
  210.          {
  211.             for(var _loc16_ in this.styleTable[propName].coloredMCs)
  212.             {
  213.                var _loc4_ = new Color(this.styleTable[propName].coloredMCs[_loc16_]);
  214.                if(this.styleTable[propName].value == undefined)
  215.                {
  216.                   var _loc5_ = {ra:"100",rb:"0",ga:"100",gb:"0",ba:"100",bb:"0",aa:"100",ab:"0"};
  217.                   _loc4_.setTransform(_loc5_);
  218.                }
  219.                else
  220.                {
  221.                   _loc4_.setRGB(value);
  222.                }
  223.             }
  224.          }
  225.       }
  226.       this.styleTable[propName].useGlobal = _loc18_;
  227.    }
  228. };
  229. FUIComponentClass.prototype.registerSkinElement = function(skinMCRef, propName)
  230. {
  231.    if(this.styleTable[propName] == undefined)
  232.    {
  233.       this.styleTable[propName] = new Object();
  234.       this.styleTable[propName].useGlobal = true;
  235.    }
  236.    if(this.styleTable[propName].coloredMCs == undefined)
  237.    {
  238.       this.styleTable[propName].coloredMCs = new Object();
  239.    }
  240.    this.styleTable[propName].coloredMCs[skinMCRef] = skinMCRef;
  241.    if(this.styleTable[propName].value != undefined)
  242.    {
  243.       var _loc4_ = new Color(skinMCRef);
  244.       _loc4_.setRGB(this.styleTable[propName].value);
  245.    }
  246. };
  247. _global.FStyleFormat = function()
  248. {
  249.    this.nonStyles = {listeners:true,isGlobal:true,isAStyle:true,addListener:true,removeListener:true,nonStyles:true,applyChanges:true};
  250.    this.listeners = new Object();
  251.    this.isGlobal = false;
  252.    if(arguments.length > 0)
  253.    {
  254.       for(var _loc3_ in arguments[0])
  255.       {
  256.          this[_loc3_] = arguments[0][_loc3_];
  257.       }
  258.    }
  259. };
  260. _global.FStyleFormat.prototype = new Object();
  261. FStyleFormat.prototype.addListener = function()
  262. {
  263.    var _loc3_ = 0;
  264.    while(_loc3_ < arguments.length)
  265.    {
  266.       var _loc4_ = arguments[_loc3_];
  267.       this.listeners[arguments[_loc3_]] = _loc4_;
  268.       for(var _loc5_ in this)
  269.       {
  270.          if(this.isAStyle(_loc5_))
  271.          {
  272.             _loc4_.updateStyleProperty(this,_loc5_.toString());
  273.          }
  274.       }
  275.       _loc3_ = _loc3_ + 1;
  276.    }
  277. };
  278. FStyleFormat.prototype.removeListener = function(component)
  279. {
  280.    this.listeners[component] = undefined;
  281.    for(var _loc4_ in this)
  282.    {
  283.       if(this.isAStyle(_loc4_))
  284.       {
  285.          if(component.styleTable[_loc4_].useGlobal == this.isGlobal)
  286.          {
  287.             component.styleTable[_loc4_].useGlobal = true;
  288.             var _loc3_ = !this.isGlobal ? globalStyleFormat[_loc4_] : undefined;
  289.             component.setStyleProperty(_loc4_,_loc3_,true);
  290.          }
  291.       }
  292.    }
  293. };
  294. FStyleFormat.prototype.applyChanges = function()
  295. {
  296.    var _loc6_ = 0;
  297.    for(var _loc5_ in this.listeners)
  298.    {
  299.       var _loc3_ = this.listeners[_loc5_];
  300.       if(arguments.length > 0)
  301.       {
  302.          var _loc4_ = 0;
  303.          while(_loc4_ < arguments.length)
  304.          {
  305.             if(this.isAStyle(arguments[_loc4_]))
  306.             {
  307.                _loc3_.updateStyleProperty(this,arguments[_loc4_]);
  308.             }
  309.             _loc4_ = _loc4_ + 1;
  310.          }
  311.       }
  312.       else
  313.       {
  314.          for(_loc4_ in this)
  315.          {
  316.             if(this.isAStyle(_loc4_))
  317.             {
  318.                _loc3_.updateStyleProperty(this,_loc4_.toString());
  319.             }
  320.          }
  321.       }
  322.    }
  323. };
  324. FStyleFormat.prototype.isAStyle = function(name)
  325. {
  326.    return !this.nonStyles[name] ? true : false;
  327. };
  328.